﻿using System;
using System.ComponentModel.Composition;
using MediaAssistant.Constants;
using MediaAssistant.Controls.BottomPanel;
using MediaAssistant.Controls.LeftPanel;
using MediaAssistant.Controls.Library;
using MediaAssistant.Controls.MovieActionToolBar;
using MediaAssistant.Controls.MovieDetail;
using MediaAssistant.Controls.MovieList;
using MediaAssistant.Controls.MovieMiddlePanel;
using MediaAssistant.Controls.MovieMiddleToolBar;
using MediaAssistant.Controls.MovieSearchControl;
using MediaAssistant.Controls.MovieThumbnails;
using MediaAssistant.Controls.MusicList;
using MediaAssistant.Controls.MusicMiddlePanel;
using MediaAssistant.Controls.MusicSearchControl;
using MediaAssistant.Controls.PlayerControl;
using MediaAssistant.Controls.PlayingMusicInfo;
using MediaAssistant.Controls.StatusMessageBar;
using MediaAssistant.Controls.TopPanel;
using MediaAssistant.Helper;
using MediaAssistant.Management;
using MefBasic;
using Microsoft.Practices.Composite.MefExtensions.Modularity;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;

namespace MediaAssistant
{
    [ModuleExport(typeof(MainModule))]
    public class MainModule:IModule
    {
        [Import]
        private IRegionManager RegionManager { get; set; }
        [Import]
        private LeftPanelPresenter LeftPanelPresenter { get; set; }
        [Import]
        private TopPanelPresenter TopPanelPresenter { get; set; }
        [Import]
        private BottomPanelPresenter BottomPanelPresenter { get; set; }
        [Import]
        protected MusicMiddlePanelPresenter MusicMiddlePanelPresenter { get; set; }
        [Import]
        protected MovieMiddlePanelPresenter MovieMiddlePanelPresenter { get; set; }
        [Import]
        protected MusicListPresenter MusicListPresenter { get; set; }
        [Import]
        protected LibraryPresenter LibraryPresenter { get; set; }
        [Import]
        protected PlayerControlPresenter PlayerControlPresenter { get; set; }
        [Import]
        protected PlayingMusicInfoPresenter PlayingMusicInfoPresenter { get; set; }
        [Import]
        protected MusicSearchControlPresenter MusicSearchControlPresenter { get; set; }
        [Import]
        public StatusMessageBarPresenter StatusMessageBarPresenter { get; set; }
        [Import]
        public MovieDetailPresenter MovieDetailPresenter { get; set; }
        [Import]
        private MovieMiddleToolBarPresenter MovieMiddleToolBarPresenter { get; set; } 
        [Import]
        protected MovieListPresenter MovieListPresenter { get; set; }
        [Import]
        protected MovieThumbnailsPresenter MovieThumbnailsPresenter { get; set; }
        [Import]
        protected MovieSearchControlPresenter MovieSearchControlPresenter { get; set; }
        [Import]
        private Lazy<LibraryManager> LibraryManager { get; set; }
        [Import]
        public MovieActionToolBarPresenter MovieActionToolBarPresenter { get; set; }

        #region Implementation of IModule

        public void Initialize()
        {
            RegionManager.Regions[RegionNames.LeftRegion].Add(LeftPanelPresenter.View);
            RegionManager.Regions[RegionNames.TopRegion].Add(TopPanelPresenter.View);
            RegionManager.Regions[RegionNames.MiddleRegion].Add(MusicMiddlePanelPresenter.View);
            RegionManager.Regions[RegionNames.MiddleRegion].Add(MovieMiddlePanelPresenter.View);
            
            RegionManager.Regions[RegionNames.BottomRegion].Add(BottomPanelPresenter.View);
            
            RegionManager.Regions[MediaAssistantRegionNames.MovieMiddleToolBar].Add(MovieMiddleToolBarPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.SearchRegion].Add(MovieSearchControlPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.MovieActionToolBar].Add(MovieActionToolBarPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.MovieDetailPanel].Add(MovieDetailPresenter.View);
            
            RegionManager.Regions[MediaAssistantRegionNames.MovieResultResion].Add(MovieListPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.MovieResultResion].Add(MovieThumbnailsPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.MovieResultResion].Activate(MovieListPresenter.View);

            RegionManager.Regions[MediaAssistantRegionNames.LibraryRegion].Add(LibraryPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.MusicResultResion].Add(MusicListPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.StatusBarRegion].Add(StatusMessageBarPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.SearchRegion].Add(MusicSearchControlPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.MusicListBar].Add(PlayerControlPresenter.View);
            RegionManager.Regions[MediaAssistantRegionNames.MusicListBar].Add(PlayingMusicInfoPresenter.View);

            LibraryManager.Value.ActivateLastResultTypeViews(RegistryHelper.LastResultType);
        }

        #endregion
    }
}
